﻿@model VehicleOOBWeb.Models.Vehicle

@{
    ViewBag.Title = "Thêm mới thông xin xe bày bán";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/Content/jquery.fileupload-ui.css" rel="stylesheet" />
<script src="~/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    var CKEDITOR_BASEPATH = '/ckeditor/';
</script>

<h2>Thông tin xe cần thêm</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <table style="width: 100%">
        <tr>
            <td>@Html.Label("Loại xe:")</td>
            <td>
                <select id="vehicle_type" name="vehicle_type">
                    @foreach (string vt in ViewBag.VehicleTypes)
                    {
                        <option value="@vt">@vt</option>
                    }
                </select>
            </td>
        </tr>
        <tr>
            <td class="editor-label">
                @Html.Label("Hãng xe:")
            </td>
            <td class="editor-field">
                <select id="manufacturer_code" name="manufacturer_code">
                    @foreach (VehicleOOBWeb.Models.Manufacturer mf in ViewBag.Manufacturers)
                    {
                        <option value="@mf.manufacturer_code">@mf.manufacturer_name</option>
                    }
                </select>
            </td>
        </tr>
        <tr>
            <td class="editor-label">
                @Html.Label("Tên:")
            </td>
            <td class="editor-field">
                @Html.EditorFor(model => model.name)
            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.name)
            </td>
        </tr>

        <tr>
            <td class="editor-label">
                @Html.Label("Giá bán:")
            </td>
            <td class="editor-field">
                <input type="text" id="price" name="price" value="" style="width: 100px" />
            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.price)
            </td>
        </tr>
        <tr>
            <td class="editor-label">
                @Html.Label("Số lượng:")
            </td>
            <td class="editor-field">
                <input type="text" id="quantity" name="quantity" value="" style="width: 100px" />
            </td>
        </tr>
        <tr>
            <td class="editor-label">
                @Html.Label("Mô tả:")
            </td>
            <td class="editor-field">
                <textarea id="description" name="description" style="width: 90%" rows="3"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.description)
            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.quantity)
            </td>
        </tr>
        <tr>
            <td class="editor-label" colspan="2">
                @Html.Label("Thông tin:")
            </td>
        </tr>
        <tr>
            <td class="editor-field" colspan="2">
                <textarea id="info" name="info"></textarea>

                <script type="text/javascript">
                    CKEDITOR.replace('info');
                </script>

            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.info)
            </td>
        </tr>
        <tr>
            <td class="editor-label">
                @Html.Label("Ngày sản xuất:")
            </td>
            <td class="editor-field">
                <input type="text" id="release_date" name="release_date" value="" style="width: 100px" />
            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.release_date)
            </td>
        </tr>
        <tr>
            <td class="editor-label">
                @Html.Label("Ảnh đại diện:")
            </td>
            <td class="editor-field">
                <table border="0" style="width: 100%">
                    <tr>
                        <td>
                            <input type="text" id="image" name="image" value="" style="width: 98%" /></td>
                        <td style="width: 90px;">
                            <input id="fileupload" type="file" name="files[]" style="width: 85px;">
                            <span id="progress"></span></td>
                    </tr>
                </table>


            </td>
        </tr>

        <tr>
            <td colspan="2" class="editor-error">
                @Html.ValidationMessageFor(model => model.manufacturer_code)
            </td>
        </tr>
        <tr>
            <td colspan="2" class="editor-button">
                <input type="submit" value="Create" />
            </td>
        </tr>
    </table>
}

<div>
    @Html.ActionLink("Về trang quản lý", "Manager")
</div>

<script src="~/Scripts/jquery.ui.widget.js"></script>
<script src="~/Scripts/jquery.iframe-transport.js"></script>
<script src="~/Scripts/jquery.fileupload.js"></script>
<script type="text/javascript">
    /*jslint unparam: true */
    /*global window, $ */
    $(function () {
        'use strict';
        // Change this to the location of your server-side upload handler:
        var url = '/uploadfile.ashx';
        $('#fileupload').fileupload({
            url: url,
            dataType: 'json',
            done: function (e, data) {
                $.each(data.result.files, function (index, file) {
                    $('#image').val('/images/cars/' + file.name);
                });
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress').text(progress + '%');
            }
        }).prop('disabled', !$.support.fileInput)
            .parent().addClass($.support.fileInput ? undefined : 'disabled');
    });
</script>

@section Scripts {

    @Scripts.Render("~/bundles/jqueryval")
}
